using UnityEngine;

public class PlayerCollector : MonoBehaviour
{
    private PlayerStats playerStats;

    void Awake()
    {
        playerStats = GetComponent<PlayerStats>();
    }

    // 当玩家的碰撞体进入一个触发器时被调用
    void OnTriggerEnter2D(Collider2D other)
    {
        // 检查碰到的是否是经验宝石
        if (other.CompareTag("ExperienceGem"))
        {
            // 获取宝石的经验值
            int expValue = other.GetComponent<ExperienceGem>().experienceValue;
            
            // 把经验加给玩家
            playerStats.AddExperience(expValue);

            // 销毁宝石
            Destroy(other.gameObject);
        }
    }
}